/** @namespace app.model.Vps */
module.exports = app => {
  const {STRING, TINYINT, DATE, INTEGER, JSON} = app.Sequelize;
  const Vps = app.model.define('vps', {
    ip: {type: STRING, allowNull: false, unique: 'ip'},
    user: {type: STRING, allowNull: false},
    password: {type: STRING, allowNull: false},

    // 状态 -2失去连接 -1无法登入服务器 0初始化中 1初始化成功 2下载代码中 3下载代码成功 4成功连入分布式系统
    status: {type: TINYINT, defaultValue: 0},

    status_num: {
      type: JSON,
      defaultValue: {
        spider: {finish: 0, wait: 0, error: 0},
        save: {finish: 0, wait: 0, error: 0},
      },
    },
    token: {type: STRING},//进入服务器的密钥
    socket_id: {type: STRING},//socket的id
    last_update_code_at: {type: DATE},//最后更新代码的时间
  }, {
    freezeTableName: true,
    tableName: 'spider_vps',
  });

  return Vps;
};